package com.fdb.efp.console.api.rest;

import com.fdb.basic.framework.core.constant.ResponseData;
import com.fdb.basic.framework.web.controller.AbstractController;
import com.fdb.efp.console.api.service.RiskmUtilService;
import com.fdb.efp.console.service.facade.OutsTaskDistrMainService;
import com.fdb.efp.console.service.vo.OutsTaskDistrMainVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class OutsTaskDistrMainController extends AbstractController {

    @Autowired
    @Qualifier("outsTaskDistrMainService")
    private OutsTaskDistrMainService outsTaskDistrMainService;

    @Autowired
    private RiskmUtilService riskmUtilService;

    /**
     * 列表数据查询
     *
     * @param vo
     * @return
     */
    @RequestMapping(value = "/outs/task/distr/mains", method = RequestMethod.POST)
    public @ResponseBody
    ResponseData<List<OutsTaskDistrMainVO>> queryOutsTaskDistrMainAll(@RequestBody OutsTaskDistrMainVO vo) {
        setUserInfoToVO(vo);
        List<OutsTaskDistrMainVO> outputVo = outsTaskDistrMainService.queryAllByConditions(vo);
        /**Map<String, String> dataRuleTypeMap = sRoleDataRuleService.getDataRuleType(httpRequest.getRequestURI(), getUserRoles());
        vo.setPrdCodebyBaseInfo(dataRuleTypeMap == null ? null : dataRuleTypeMap.get(PubConstant.PRD_CODE));
        DataRuleType dataRuleType = DataRuleType.getDataRuleType(dataRuleTypeMap == null ? null : dataRuleTypeMap.get(PubConstant.PERMIS_TYPE));
        setUserInfoToVO(vo);
        // 根据权限方案调用不同的方案进行数据查询
        switch (dataRuleType) {
            case Owner:
                outputVo = outsTaskDistrMainService.queryAllOwner(vo);
                break;
            case CurrOrg:
                outputVo = outsTaskDistrMainService.queryAllCurrOrg(vo);
                break;
            case CurrDownOrg:
                outputVo = outsTaskDistrMainService.queryAllCurrDownOrg(vo);
                break;
            default:
                outputVo = outsTaskDistrMainService.queryAllOwner(vo);
                break;
        }*/
        riskmUtilService.displayOrgName(outputVo,"opOrgCode","opOrgName");
        riskmUtilService.displayUserName(outputVo,"opUserCode","opUserName");
        return getResponseData(outputVo);
    }

    /**
     * 根据主键查询详情
     *
     * @return
     */
    @RequestMapping(value = "/outs/task/distr/main", method = RequestMethod.GET)
    public @ResponseBody ResponseData<OutsTaskDistrMainVO> queryByCondition(OutsTaskDistrMainVO vo) {
        OutsTaskDistrMainVO outputVo = outsTaskDistrMainService.queryByPk(vo);
        return getResponseData(outputVo);
    }

    /**
     * 根据主键删除信息
     *
     * @param inOutsTaskDistrMainVo
     * @return
     */
    @RequestMapping(value = "/outs/task/distr/main", method = RequestMethod.DELETE)
    public @ResponseBody
    ResponseData<Integer> deleteByPk(@RequestBody OutsTaskDistrMainVO inOutsTaskDistrMainVo) {
        int outputVo = outsTaskDistrMainService.deleteByPk(inOutsTaskDistrMainVo);
        return getResponseData(outputVo);

    }

    /**
     * 根据主键更新信息
     *
     * @param inOutsTaskDistrMainVo
     * @return
     */
    @RequestMapping(value = "/outs/task/distr/main", method = RequestMethod.PUT)
    public @ResponseBody
    ResponseData<Integer> updateByPk(@RequestBody OutsTaskDistrMainVO inOutsTaskDistrMainVo) {
        int outputVo = outsTaskDistrMainService.updateByPk(inOutsTaskDistrMainVo);
        return getResponseData(outputVo);

    }

    /**
     * 新增数据
     *
     * @param inOutsTaskDistrMainVo
     * @return
     */
    @RequestMapping(value = "/outs/task/distr/main", method = RequestMethod.POST)
    public @ResponseBody
    ResponseData<Integer> insertOutsTaskDistrMain(@RequestBody OutsTaskDistrMainVO inOutsTaskDistrMainVo) {
        int outputVo = outsTaskDistrMainService.insertOutsTaskDistrMain(inOutsTaskDistrMainVo);
        return getResponseData(outputVo);

    }

}
